<template>
	<view>
		<!-- 问卷调查非网页版 -->
		<u-navbar title="合伙人邀请" placeholder @leftClick="onBackClick"  leftIconColor="#fff" bgColor="#111111"
			:titleStyle="titleStyle">
			<!-- <view slot="right">反馈记录</view> -->
		</u-navbar>
		<view class="nameV">
			<text class="nameTv1">*</text>
			<text class="nameTv2">姓名</text>
			<view class="nameTv3">
				<input placeholder="请输入姓名" v-model="name" />
			</view>
		</view>
		<view class="nameV">
			<text class="nameTv1">*</text>
			<text class="nameTv2">手机号</text>
			<view class="nameTv3">
				<input placeholder="请输入手机号" v-model="mobile" />
			</view>
		</view>

		<view class="sumTv" @click="onSumClick">提交</view>
		<!-- <view class="sumTvjilu" @click="jilu"><text>反馈记录</text></view> -->
		
		<ns-login ref="login" @saveUserInfo="onUserInfoClick"></ns-login>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				id: '',
				formList: [],
				mName: '',
				mGmail: '',
				shareId: "", //门店id
				roleId: "", //分享人用户id
				details:{},
				fileList1: [],
				fileList2: [],
				code_a:'',//身份证正面
				code_atwo:'',//身份证正面
				code_b:'',//身份证反面
				code_btwo:'',//身份证反面
				name:'',//姓名
				mobile:'',//联系方式
				headimg:''
			}
		},
		// onShareAppMessage: function(res) {
		// 	console.log("开始分享接收参数--->" + JSON.stringify(res))
		// 	let shopId = this.id;
		// 	let userId = uni.getStorageSync("user_info_id");
		// 	return {
		// 		title: this.details.sharetitle,
		// 		imageUrl: this.details.shareimage,
		// 		path: `shop/bodyBuilding/Questionnaire?id=` + shopId + `&userid=` + userId, // 分享后打开的页面
		// 		success: function(res) {
		// 			console.log("转发成功")
		// 		},
		// 		fail: function(res) {
		// 			console.log("转发失败")
		// 		}
		// 	}
		// },
		onLoad(e) {
			// this.id = e.id;
			this.shareId = e.share_id;
			this.roleId = e.role_id;
			this.gethuixian()
		},
		methods: {
			gethuixian(){
				this.$api.getPartnerInfo({
				}).then((res) => {
					console.log(res)
					let info = res.info
					if(info.name){
						this.name = info.name
					}
					if(info.mobile){
						this.mobile = info.mobile
					}
					if(info.code_a){
						this.code_a = info.code_a
						this.code_atwo = this.$api.getBaseUrl()+info.code_a
						
					}
					if(info.code_b){
						this.code_b = info.code_b
						this.code_btwo = this.$api.getBaseUrl()+info.code_b
					}
				}).catch((e) => {

				})
			},
			onBackClick() {
				let pages = getCurrentPages();
				if (pages[pages.length - 2]) {
					//如果有上一页，就返回上一页
					wx.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/app/Home'
					});
				}
			
			},
			onUserInfoClick(e) {
				if (e.code == 200) {
					this.getForm();
				} else {
			
				}
			},
			getForm() {
				this.$api.getFormId({
					id: this.id
				}).then((res) => {
					res.list.map((item, index) => {
						item.answer = "";
					})
					this.formList = res.list;
					this.details = res.form;
				}).catch((e) => {

				})
			},
			onItemClick(data, item, index) {
				//多选
				if (data.type == "checkbox") {
					if (data.answer) {
						let answerList = data.answer.split(",");
						let isYes = -1;
						answerList.map((text, index) => {
							if (item == text) {
								isYes = index;
							}
						})
						if (isYes != -1) {
							answerList.splice(isYes, 1);
						} else {
							answerList.push(item);
						}
						data.answer = answerList.join(",");
					} else {
						data.answer = item;
					}
				} else { //单选
					data.answer = item;
				}
			},
			onSumClick() { //提交问卷调查
				// console.log(this.shareId);
				// console.log(this.roleId);
				// return;
				if (!this.name) {
					uni.$u.toast("请输入姓名")
					return
				}
				if (!this.mobile) {
					uni.$u.toast("请输入手机号")
					return
				}
			
				this.$api.addShare({
			
					name: this.name,
					mobile: this.mobile,
					role_id: this.role_id,
					share_id: this.share_id,
				}).then((res) => {
					
					uni.$u.toast(res.msg)
				}).catch((e) => {
				uni.$u.toast(e.msg)
				})
			},
			jilu(){
				this.$u.route({
						url: '/shop/New/FanKuiLIst'
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			onChooseAvatar(e) {
				this.lei = e;//1正面 2背面
				
				// this.updatetype = e
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.headimg = tempFilePaths[0];
						// this.isClick = true;
						this.unloadtou()
					}
				});
				
			},
			unloadtou(){
				let that = this;
				var data = {
					token: uni.getStorageSync("user_info_token"),
					id: uni.getStorageSync("user_info").id
				}
				uni.uploadFile({
					url: this.$api.getBaseUrl() + '/api/common/upload',
					filePath: this.headimg,
					name: 'file',
					header: data,
					success: function(res) {
						var path_str = JSON.parse(res.data);
						console.log(path_str)
						if (path_str.code == 1) {
							let uurl = path_str.data.fullurl;
							let uurltwo = path_str.data.url;
							if(that.lei == 1){
								//正面
								that.code_atwo = uurl
								that.code_a = uurltwo
							}else if(that.lei == 2){
								//背面
								that.code_b =  uurltwo
								that.code_btwo =uurl
							}
							// chat.uploadProfile(uurl)
						} else {
							uni.$u.toast(path_str.msg === undefined ? "头像修改失败" : path_str.msg)
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.titleIv{
		width: 100%;
		height: 320rpx;
	}
	.titleTv{
		color: #fff;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 30rpx;
	}
	.nameV {
		display: flex;
		align-items: center;
		background: #1F1F1F;
		margin-top: 20rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		height: 90rpx;
	}
	.nameVtwo{
		display: flex;
		flex-direction: column;
		background: #1F1F1F;
		margin-top: 20rpx;
		// padding-left: 30rpx;
		// padding-right: 30rpx;
		padding: 30rpx;
		// height: 90rpx;
	}

	.nameTv1 {
		color: #D4FF45;
	}

	.nameTv2 {
		color: #fff;
		font-size: 32rpx;
		font-weight: 700;
		margin-left: 5rpx;
	}

	.nameTv3 {
		font-size: 32rpx;
		color: #fff;
		margin-left: 20rpx;
	}

	.sumTv {
		height: 100rpx;
		margin-top: 40rpx;
		border-radius: 50px;
		background: #D4FF45;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-weight: 500;
		color: #333737;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}
	.sumTvjilu{
		position: fixed;
		width: 120rpx;
		height: 120rpx;
		bottom: 13%;
		right: 30rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #333737;
		border-radius: 50px;
		background: #D4FF45;
		display: flex;
		align-items: center;
		justify-content: center;
		
		text{
			display: inline-block;
			width: 28px;
   			line-height: 20px;

		}
	}

	.itemV {
		margin-top: 20rpx;
		background-color: #1F1F1F;
		padding: 30rpx;
	}

	.itemTv {
		color: #fff;
		font-size: 32rpx;
		font-weight: 400;
	}

	.ansV {
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}

	.ansIv {
		width: 40rpx;
		height: 40rpx;
	}
	.sc{
		width: 180rpx;
		height: 180rpx;
		border-radius: 5rpx;
		position: relative;
	}
	.scimg{
		width: 100%;
		height: 100%;
		border-radius: 5rpx;
	}

	.ansTv {
		margin-left: 10rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #fff;
	}
	/deep/.u-textarea{
		color: #fff;
		background-color: transparent !important;
	}
	/deep/.uni-textarea-textarea{
		color: #fff;
	}
</style>